#ifndef _WANGXUAN_KEY_HELPER_H_
#define _WANGXUAN_KEY_HELPER_H_


class KeyHelper{
public:
	enum KEYTYPE {UCHAR=1,UINT=4,MD5=16,UINT64=8};
	enum CONDITION {NO,GT,GE,EQ,LE,LT};
	enum DIRECTION {LEFT,RIGHT};
	
	KeyHelper();
	~KeyHelper();
	static KeyHelper* instance();
public:
	int getKeyLen();
	int getKeyCount();
	KEYTYPE getKeyType(int idx);
	int compare(const void* k1,const void* k2);

	char* format(const void* k,char* buf);
	int init(const char* config);

	void* ntoh(void* input);
	void* hton(void* input);
	void *ntohEx(void * input);

	void* ntohPoi(void *input);
	void* htonPoi(void *input);

	int conditionAnalyse(const void*key,const char* condtion,void* keyLeft,void* keyRight);//,int& direction);
	bool isConditionStatisfy(const void* k1,const void* k2,const char* condition);
private:
private:
	int keyLen;
	int keyCount;
	KEYTYPE* keys;
};

inline int KeyHelper::getKeyLen(){
	return keyLen;
}

inline int KeyHelper::getKeyCount(){
	return keyCount;
}

inline KeyHelper::KEYTYPE KeyHelper::getKeyType(int idx){
	return keys[idx];
}

inline KeyHelper* KeyHelper::instance(){
	static KeyHelper kh;
	return &kh;
}


#endif



